package leetcode.part1;

import org.junit.Test;

import java.util.Arrays;

public class S6 {
    public void rotate(int[] nums, int k) {
        k=k% nums.length;
        reverse(nums,0,nums.length-1);
        reverse(nums,0,k-1);
        reverse(nums,k,nums.length-1);
    }
    public void reverse(int[] nums,int left,int right){
        while (left<right&&right<nums.length&&left<nums.length){
            int temp=nums[left];
            nums[left]=nums[right];
            nums[right]=temp;
            left++;
            right--;
        }
    }
    @Test
    public void test(){
        int[] nums={1,2,3};
        int k=4;
        rotate(nums,k);
        System.out.println(Arrays.toString(nums));
    }
}
